package com.he1618;

import java.math.BigInteger;

public class PermissionSystem {

    // 定义权限常量
    private static final BigInteger READ_PERMISSION = new BigInteger("1");
    private static final BigInteger WRITE_PERMISSION = new BigInteger("2");
    private static final BigInteger EXECUTE_PERMISSION = new BigInteger("4");

    public static void main(String[] args) {
        // 创建用户权限
        BigInteger userPermissions = BigInteger.ZERO;

        // 授予读权限
        userPermissions = userPermissions.or(WRITE_PERMISSION);

        // 判断用户是否有写权限
        if (userPermissions.and(WRITE_PERMISSION).equals(WRITE_PERMISSION)) {
            System.out.println("用户有写权限");
        } else {
            System.out.println("用户没有写权限");
        }

        // 撤销读权限
        userPermissions = userPermissions.andNot(READ_PERMISSION);

        // 判断用户是否有执行权限
        if (userPermissions.and(EXECUTE_PERMISSION).equals(EXECUTE_PERMISSION)) {
            System.out.println("用户有执行权限");
        } else {
            System.out.println("用户没有执行权限");
        }
    }
}
